
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 12/20/2013 11:07:30
-- Generated from EDMX file: F:\Projekty\Testing\ConsoleApplication5\PiiSWebAPI\PiiSDataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [piis_db];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'FeatureSet'
CREATE TABLE [dbo].[FeatureSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Movies_Features'
CREATE TABLE [dbo].[Movies_Features] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [MovieId] int  NOT NULL,
    [FeatureId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'FeatureSet'
ALTER TABLE [dbo].[FeatureSet]
ADD CONSTRAINT [PK_FeatureSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Movies_Features'
ALTER TABLE [dbo].[Movies_Features]
ADD CONSTRAINT [PK_Movies_Features]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [MovieId] in table 'Movies_Features'
ALTER TABLE [dbo].[Movies_Features]
ADD CONSTRAINT [FK_Movies_FeaturesMovie]
    FOREIGN KEY ([MovieId])
    REFERENCES [dbo].[MovieSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Movies_FeaturesMovie'
CREATE INDEX [IX_FK_Movies_FeaturesMovie]
ON [dbo].[Movies_Features]
    ([MovieId]);
GO

-- Creating foreign key on [FeatureId] in table 'Movies_Features'
ALTER TABLE [dbo].[Movies_Features]
ADD CONSTRAINT [FK_Movies_FeaturesFeature]
    FOREIGN KEY ([FeatureId])
    REFERENCES [dbo].[FeatureSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Movies_FeaturesFeature'
CREATE INDEX [IX_FK_Movies_FeaturesFeature]
ON [dbo].[Movies_Features]
    ([FeatureId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------